package com.atguigu.mall.product.service.impl;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.atguigu.mall.product.dao.AttrAttrgroupRelationDao;
import com.atguigu.mall.product.entity.AttrAttrgroupRelationEntity;
import com.atguigu.mall.product.service.AttrAttrgroupRelationService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void deleteByGroupIds(List<Long> attrGroupIds) {
        LambdaQueryWrapper<AttrAttrgroupRelationEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(AttrAttrgroupRelationEntity::getAttrGroupId,attrGroupIds);
        this.remove(wrapper);
    }

    @Override
    public void deleteByAttrId(Long attrId) {
        LambdaQueryWrapper<AttrAttrgroupRelationEntity> wapper = new LambdaQueryWrapper<>();
        wapper.eq(AttrAttrgroupRelationEntity::getAttrId,attrId);
        this.baseMapper.delete(wapper);
    }

    @Override
    public void saveAttrAttrgroupRelation(Long attrId, Long attrGroupId) {
        AttrAttrgroupRelationEntity relation  = new AttrAttrgroupRelationEntity();
        relation.setAttrId(attrId);
        relation.setAttrGroupId(attrGroupId);
        this.baseMapper.insert(relation);
    }

    @Override
    public List<AttrAttrgroupRelationEntity> queryRelByGroupIds(List<Long> groupIds) {
        LambdaQueryWrapper<AttrAttrgroupRelationEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(AttrAttrgroupRelationEntity::getAttrGroupId,groupIds);


            return this.baseMapper.selectList(wrapper);
    }

}